/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：江苏省苏州市苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 版本: 权力阳光数据管理平台_1.0
 * <p>
 * 作者: 110510(朱伟家)
 * <p>
 * <p>
 * 文件名: ReportController.java
 * <p>
 * 类产生时间:2011-11-2 下午07:30:48
 * <p>
 * 负责人: 110510(朱伟家)
 * <p>
 * 所在组: 权力阳光数据管理平台
 * <p>
 * 所在部门: 开发一部-技术二部
 * <p>
 * email：zhuwj@oceansoft.com.cn
 * <p>
 * <p>
 */

package com.oceansoft.core.controller;

import java.io.File;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hui.platform.basic.logger.Logger;
import com.hui.platform.kernel.service.HuiServiceManager;
import com.oceansoft.core.service.ReportService;

@Controller
@RequestMapping(value = "/report.do")
public class ReportController {


	// 根据类型下载不同的表格
	public static final String REPORT_LX_EXP =    "method=getReportBylx_exp";


	private static Logger logger = (Logger) HuiServiceManager.getInstance()
			.getService(Logger.class.toString());
	private static Map<String, String> lxMap = new HashMap<String, String>();
	
	static {
		// 监控节点汇总
		lxMap.put("1", "警务流程监控节点汇总表");
		lxMap.put("1_page", "jkqkfl");
	}

	@Autowired
	ReportService reportService;

	/**
	 * 表格下载
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(params = REPORT_LX_EXP)
	public void getReportBylxExp(HttpServletRequest request,
			HttpServletResponse response) {
		String lx = request.getParameter("lx");
		String configName = lxMap.get(lx) + ".xml";
		String title =  lxMap.get(lx);
		String filename = title + ".xls";
		OutputStream outStream = null;
		try
		{
		String tempfileName = new String(filename.getBytes("GBK"),
				"ISO8859_1");
		response.setContentType("application/vnd.ms-excel");
		response.addHeader("Content-Disposition", "attachment; filename="
				+ tempfileName);
		// 获取系统所在服务器本地路径
		String webPath = request.getSession().getServletContext()
				.getRealPath("/");
		// 创建一个存放下载文件的临时目录
		String tempFile = "tempDownLoad";
		File tempDir = new File(webPath + "/" + tempFile);
		if (!tempDir.exists()) {
			tempDir.mkdirs();
		}
		outStream = response.getOutputStream();
		// 处理时间
		List list = null;
		list = (List) request.getSession().getAttribute(lxMap.get(lx));
		Map customMap = new HashMap();
		customMap.put("title", title + ",0,0");
		reportService.exportByCondition(outStream, list, configName,
				customMap);
		outStream.flush();
		outStream.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
		// return "report/blank";
	}
	

}
